//
//  YunDanCenterExtraFeeViewController.m
//  阿帕
//
//  Created by mac on 2020/3/13.
//  Copyright © 2020 GCY. All rights reserved.
//

#import "YunDanCenterExtraFeeViewController.h"

@interface YunDanCenterExtraFeeViewController ()

@end

@implementation YunDanCenterExtraFeeViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.navigationItem.title = @"其他费用";
    
    self.view.backgroundColor = BackgroundColor;
    
    [self networkRequest];
}

- (void)setupBaseView:(NSArray *)dataArr {
    
    NSArray *titleArr = @[@"收入",@"费用类型",@"费用备注"];

    UIView *topBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 10, ScreenW, 45)];
    topBgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:topBgView];
    
    UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 100, 45)];
    textLabel.font = font(14);
    textLabel.text = @"合计";
    textLabel.textColor = Dark_TextColor;
    [topBgView addSubview:textLabel];
    
    UILabel *valueLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenW-15-100, 0, 100, 45)];
    valueLabel.font = font(14);
    valueLabel.text = CJStringWithFormat(@"%@元", _totalAmount);
    valueLabel.textColor = Dark_TextColor;
    valueLabel.tag = 10;
    valueLabel.textAlignment = NSTextAlignmentRight;
    [topBgView addSubview:valueLabel];
    
    for (int i=0; i<dataArr.count; i++) {
        
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 65 + 125*i, ScreenW, 120)];
        bgView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:bgView];
        
        for (int j=0; j<3; j++) {
            
            UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 40*j, 80, 40)];
            textLabel.font = font(14);
            textLabel.text = titleArr[j];
            textLabel.textColor = Dark_TextColor;
            [bgView addSubview:textLabel];
            
            UILabel *valueLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 40*j, ScreenW-115, 40)];
            valueLabel.font = font(14);
            valueLabel.textColor = Dark_TextColor;
            valueLabel.textAlignment = NSTextAlignmentRight;
            [bgView addSubview:valueLabel];
            
            if (j==0) {
                
                if ([dataArr[i][@"extraPayType"] integerValue] == 1) {
                    textLabel.text = @"支出";
                    valueLabel.textColor = Red_Color;
                    valueLabel.text = [NSString nullToString:CJStringWithFormat(@"-%@元", dataArr[i][@"extraFeeAmount"])];
                } else {
                    textLabel.text = @"收入";
                    valueLabel.textColor = Dark_TextColor;
                    valueLabel.text = [NSString nullToString:CJStringWithFormat(@"+%@元", dataArr[i][@"extraFeeAmount"])];
                }
                
            } else if (j==1) {
                valueLabel.text = [NSString nullToString:CJStringWithFormat(@"%@", dataArr[i][@"extraFeeName"])];
            } else {
                valueLabel.text = [NSString nullToString:CJStringWithFormat(@"%@", dataArr[i][@"extraFeeRemark"])];
            }
                    
        }
        
    }
}

- (void)networkRequest {
    WEAKSELF
    [HTTPManager getNetworkRequest:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-tms-api",[ReAddressDynamic shared].baseUrl], ORDEREXTRAFEE) withParameter:@{@"orderCode": _code, @"token":[UserDefaultUtil valueForKey:USER_TOKEN],} withVC:self netName:@"其他费用详情" success:^(id response, NSString *msg) {
        
        [weakSelf setupBaseView:response[@"records"]];
        
    } failure:^(NSInteger code, NSString *msg) {
        
    }];
}

@end
